pub fn time_info(date_str: &str) -> String {
    let parts: Vec<&str> = date_str.split('-').collect();
    if parts.len() != 3 {
        return "Invalid date format".to_string();
    }
    let year: i32 = parts[0].parse().unwrap();
    let month: i32 = parts[1].parse().unwrap();
    let day: i32 = parts[2].parse().unwrap();
    let is_leap = is_leap_year(year);
    let mut days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if is_leap {
        days_in_month[1] = 29;
    }

    let day_of_year = calculate_day_of_year(&days_in_month, month, day);
    // 计算当年剩余天数
    let total_days_in_year = if is_leap { 366 } else { 365 };
    let days_left_in_year = total_days_in_year - day_of_year;
    let week_number = calculate_iso_week_number(year, month, day, days_left_in_year);
    let (cny_month, cny_day) = get_chinese_new_year_date(year);

    let mut days_until_cny = days_between_dates(year, month, day, year, cny_month, cny_day);
    if days_until_cny < 0 {
        let next_year = year + 1;
        let (next_cny_month, next_cny_day) = get_chinese_new_year_date(next_year);
        days_until_cny =
            days_between_dates(year, month, day, next_year, next_cny_month, next_cny_day);
    }
    format!(
        "{},{},{}",
        week_number,
        days_left_in_year,
        days_until_cny - 1
    )
}

fn calculate_iso_week_number(year: i32, month: i32, day: i32, left_day: i32) -> i32 {
    let weekday = get_weekday(year, month, day);
    let day_of_year = get_day_of_year(year, month, day);
    let day_diff = day_of_year + (3 - weekday);
    let week_number = (day_diff / 7) + 1;
    // 查看是否是明年的第一周
    if 4 - weekday > left_day {
        return 1;
    }
    week_number
}

fn get_day_of_year(year: i32, month: i32, day: i32) -> i32 {
    let mut days = day;
    let mut days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    if is_leap_year(year) {
        days_in_month[1] = 29;
    }

    for i in 0..(month - 1) as usize {
        days += days_in_month[i];
    }

    days
}

fn get_weekday(year: i32, month: i32, day: i32) -> i32 {
    // 使用蔡勒公式
    let mut y = year;
    let mut m = month;
    if m < 3 {
        m += 12;
        y -= 1;
    }
    let k = y % 100;
    let j = y / 100;
    let h = (day + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
    let d = ((h + 5) % 7) + 1;
    d
}

fn is_leap_year(year: i32) -> bool {
    (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
}

fn calculate_day_of_year(days_in_month: &[i32; 12], month: i32, day: i32) -> i32 {
    let mut day_of_year = day;
    for i in 0..(month as usize - 1) {
        day_of_year += days_in_month[i];
    }
    day_of_year
}

fn get_chinese_new_year_date(year: i32) -> (i32, i32) {
    match year {
        2000 => (2, 5),
        2001 => (1, 24),
        2002 => (2, 12),
        2003 => (2, 1),
        2004 => (1, 22),
        2005 => (2, 9),
        2006 => (1, 29),
        2007 => (2, 18),
        2008 => (2, 7),
        2009 => (1, 26),
        2010 => (2, 14),
        2011 => (2, 3),
        2012 => (1, 23),
        2013 => (2, 10),
        2014 => (1, 31),
        2015 => (2, 19),
        2016 => (2, 8),
        2017 => (1, 28),
        2018 => (2, 16),
        2019 => (2, 5),
        2020 => (1, 25),
        2021 => (2, 12),
        2022 => (2, 1),
        2023 => (1, 22),
        2024 => (2, 10),
        2025 => (1, 29),
        2026 => (2, 17),
        2027 => (2, 6),
        2028 => (1, 26),
        2029 => (2, 13),
        2030 => (2, 3),
        2031 => (1, 23),
        2032 => (2, 11),
        2033 => (1, 31),
        2034 => (2, 19),
        2035 => (2, 8),
        2036 => (1, 28),
        2037 => (2, 15),
        2038 => (2, 4),
        2039 => (1, 24),
        2040 => (2, 12),
        2041 => (2, 1),
        2042 => (1, 22),
        2043 => (2, 10),
        2044 => (1, 30),
        2045 => (2, 17),
        2046 => (2, 6),
        2047 => (1, 26),
        2048 => (2, 14),
        2049 => (2, 2),
        2050 => (1, 23),
        _ => (2, 5),
    }
}

fn days_between_dates(y1: i32, m1: i32, d1: i32, y2: i32, m2: i32, d2: i32) -> i32 {
    let total_days1 = total_days_since_0000(y1, m1, d1);
    let total_days2 = total_days_since_0000(y2, m2, d2);
    total_days2 - total_days1
}

fn total_days_since_0000(year: i32, month: i32, day: i32) -> i32 {
    let mut days = day;

    for y in 0..year {
        days += if is_leap_year(y) { 366 } else { 365 };
    }

    let mut days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if is_leap_year(year) {
        days_in_month[1] = 29;
    }

    for m in 0..(month as usize - 1) {
        days += days_in_month[m];
    }

    days
}
